home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1996 February: Tool Chest / Apple Developer CD Series Tool Chest February 1996 (Apple Computer)(1996).iso / Sample Code / AOCE Sample Code / PowerTalk Access Modules / Sample SMSAM / SampleSMSAM Source / BuildingBlocks / UAppleEvents.h < prev    next >
Encoding:
C/C++ Source or Header  |  1995-07-28  |  7.7 KB  |  163 lines  |  [TEXT/MPS ]

  1. /*
  2.     File:        UAppleEvents.h
  3.  
  4.     Copyright:    © 1991-1994 by Apple Computer, Inc.
  5.                 All rights reserved.
  6.  
  7.     Part of the AOCE Sample SMSAM Package.  Consult the license
  8.     which came with this software for your specific legal rights.
  9.  
  10. */
  11.  
  12.  
  13.  
  14. #ifndef __UAPPLEEVENTS__
  15. #define __UAPPLEEVENTS__
  16.  
  17. #ifndef __APPLEEVENTS__
  18. #include "AppleEvents.h"
  19. #endif
  20.  
  21. #ifndef __DATAITEM__
  22. #include "DataItem.h"
  23. #endif
  24.  
  25. #ifndef __DIRECTOBJECT__
  26. #include "DirectObject.h"
  27. #endif
  28.  
  29. #ifndef __EDITIONS__
  30. #include "Editions.h"
  31. #endif
  32.  
  33. /***********************************|****************************************/
  34.  
  35. #pragma push
  36. #pragma segment AppleEvent
  37.  
  38. class TAddressDescription;
  39.  
  40. /***********************************|****************************************/
  41.  
  42. class TObjectList;
  43.  
  44. class TAppleEvent : public TDirectObject
  45. {
  46. public:        TAppleEvent(const AEEventClass itsEventClass, const AEEventID itsEventID, const AEAddressDesc& itsAddress, long itsSendingMode);
  47.             TAppleEvent(const AppleEvent& theMessage, Boolean freeMessage = false );
  48.  
  49.     virtual ~TAppleEvent();
  50.  
  51.     virtual TAppleEvent*             Send(OSErr& err);
  52.  
  53.     virtual  OSErr                     SetAddress(const AEAddressDesc& theAddress);
  54.     virtual  void                     SetPriority(short thePriority);
  55.     virtual  OSErr                     SetReturnID(long returnID);
  56.     virtual  void                     SetSendingMode(long sendingMode);
  57.     virtual  void                     SetTimeoutVal(long theTimeoutVal);
  58.     virtual  OSErr                     SetTransactionID(long transactionID);
  59.  
  60.     virtual OSErr                     GetAddress(AEAddressDesc& theAddress);
  61.     virtual short                     GetPriority();
  62.     virtual OSErr                     GetReturnID(long& returnID);
  63.     virtual long                     GetSendingMode();
  64.     virtual long                     GetTimeoutVal();
  65.     virtual  OSErr                     GetTransactionID(long& transactionID);
  66.  
  67.     virtual  OSErr                     ReadShort(const AEKeyword theKey, short& theValue);
  68.     virtual  OSErr                     ReadLong(const AEKeyword theKey, long& theValue);
  69.     virtual  OSErr                     ReadString(const AEKeyword theKey, char* theData);
  70.     virtual  OSErr                     ReadList(const AEKeyword theKey, const DescType theType, TObjectList& list );
  71.     virtual  OSErr                     ReadParameter(const AEKeyword theKey, const DescType desiredType, TAddressDescription& theData);
  72.  
  73.     virtual    OSErr                    ReadParameter ( const AEKeyword theKey, StringPtr str );
  74.     virtual    OSErr                    ReadParameter ( const AEKeyword key, ADataItem& value );
  75.     
  76.     virtual  OSErr                     WriteShort(const AEKeyword theKey, short theData);
  77.     virtual  OSErr                     WriteLong(const AEKeyword theKey, long theData);
  78.     virtual  OSErr                     WriteString(const AEKeyword theKey, const char* theData);
  79.     virtual  OSErr                     WriteParameter(const AEKeyword theKey, const TAddressDescription& theData);
  80.     virtual  OSErr                     WriteParameter(const AEKeyword theKey, const DescType typeCode, const void* theData, unsigned long dataSize);
  81.  
  82.     virtual    OSErr                    WriteParameter ( const AEKeyword key, const ADataItem& value );
  83.     
  84.     virtual  OSErr                     DeleteParameter(const AEKeyword theKey);
  85.  
  86.             AppleEvent                 fMessage;        // Created by IAppleEvent, Set from InitializeFromMessage
  87.             long                    fSendingMode;    // kAENoReply, kAEQueueReply, or kAEWaitReply
  88.             short                    fPriority;        // kAENormalPriority or kAEHighPriority
  89.             long                    fTimeoutVal;    // How long should we wait for a response?
  90.             Boolean                    fFreeMessage;    // If TRUE then free the message when freeing the object
  91. };
  92.  
  93. /***********************************|****************************************/
  94.  
  95. class TAddressDescription : public TDirectObject
  96. {
  97. public:        TAddressDescription ();
  98.             TAddressDescription ( DescType type, const void* data, unsigned long length );
  99.             TAddressDescription ( const AEDesc&, Boolean adoptData = false );
  100.             TAddressDescription ( const TAddressDescription& );
  101.     virtual    ~TAddressDescription ();
  102.     
  103.             TAddressDescription&    operator = ( const TAddressDescription& );
  104.             
  105.                                     operator AEDesc* ();
  106.                                     operator AEDesc& ();
  107.             
  108.             Boolean                    operator == ( const TAddressDescription& ) const;
  109.             Boolean                    operator != ( const TAddressDescription& ) const;
  110.             
  111.             AEDesc                    fData;
  112. private:    Boolean                 fAdoptData;
  113. };
  114.  
  115. /***********************************|****************************************/
  116.  
  117. extern  void InitUAppleEvents(ProcPtr dispatcher);
  118.     // Loads essential tables and starts up support for appleevents
  119.  
  120. extern pascal OSErr AppleEventsDispatch( const AppleEvent* message, const AppleEvent* reply, long info );
  121.     // The general dispatch function which is passed AEInit.  Forwards into gApplication->DispatchAppleEvents
  122.  
  123. //extern IdleProcPtr gMacAppAppleEventIdleProc;
  124.     // the default idle proc for AESend and AEInteractWithUser. Will be automatically set
  125.     // to CPoint to MacAppAppleEventIdleProc.  Set this to NULL in your code if you don't
  126.     // want it or call it from your own filter proc if you just want to add behavior.
  127.  
  128. //extern EventFilterProcPtr gMacAppAppleEventFilterProc;
  129.     // the default WaitReply filter proc for AESend. Initialized to NULL.  CPoint it at your
  130.     // own filter proc if you want to handle high level events while waiting to process another
  131.  
  132. /***********************************|****************************************/
  133.  
  134. inline TAddressDescription::operator AEDesc* () { return &fData; }
  135. inline TAddressDescription::operator AEDesc& () { return fData; }
  136. inline short TAppleEvent::GetPriority() { return fPriority; }
  137. inline OSErr TAppleEvent::GetAddress(AEAddressDesc& theAddress) { return AEGetAttributeDesc(&fMessage, keyAddressAttr, typeTargetID, &theAddress); }
  138. inline long TAppleEvent::GetSendingMode() { return fSendingMode; }
  139. inline long TAppleEvent::GetTimeoutVal() { return fTimeoutVal; }
  140. inline OSErr TAppleEvent::SetAddress(const AEAddressDesc& theAddress) { return AEPutAttributeDesc(&fMessage, keyAddressAttr, &theAddress); }
  141. inline void TAppleEvent::SetPriority(short thePriority) { fPriority = thePriority; }
  142. inline OSErr TAppleEvent::SetReturnID(long returnID) { return AEPutAttributePtr(&fMessage, keyReturnIDAttr, typeLongInteger, (Ptr) & returnID, sizeof(returnID)); }
  143. inline void TAppleEvent::SetSendingMode(long sendingMode) { fSendingMode = sendingMode; }
  144. inline void TAppleEvent::SetTimeoutVal(long theTimeoutVal) { fTimeoutVal = theTimeoutVal; }
  145. inline OSErr TAppleEvent::SetTransactionID(long transactionID) { return AEPutAttributePtr(&fMessage, keyTransactionIDAttr, typeLongInteger, (Ptr) & transactionID, sizeof(transactionID)); }
  146. inline OSErr TAppleEvent::ReadParameter(const AEKeyword theKey, const DescType desiredType, TAddressDescription& theData) { return AEGetParamDesc(&fMessage, theKey, desiredType, theData); }
  147. inline OSErr TAppleEvent::WriteShort(const AEKeyword theKey, short theData) { return AEPutParamPtr(&fMessage, theKey, typeShortInteger, (Ptr) & theData, sizeof(theData)); }
  148. inline OSErr TAppleEvent::WriteLong(const AEKeyword theKey,long theData) { return AEPutParamPtr(&fMessage, theKey, typeLongInteger, (Ptr) & theData, sizeof(theData)); }
  149. inline OSErr TAppleEvent::WriteString(const AEKeyword theKey,const char* theData) { return AEPutParamPtr(&fMessage, theKey, typeChar, (Ptr) theData, strlen(theData)); }
  150. inline OSErr TAppleEvent::WriteParameter(const AEKeyword theKey, const TAddressDescription& theData) { return AEPutParamDesc(&fMessage, theKey, ((TAddressDescription&)theData).operator AEDesc* () ); }
  151. inline OSErr TAppleEvent::WriteParameter(const AEKeyword theKey, const DescType typeCode, const void* theData, unsigned long dataSize) { return AEPutParamPtr(&fMessage, theKey, typeCode, (Ptr) theData, dataSize); }
  152. inline OSErr TAppleEvent::DeleteParameter(const AEKeyword theKey) { return AEDeleteKeyDesc(&fMessage, theKey); }
  153. inline OSErr TAppleEvent::WriteParameter ( const AEKeyword key, const ADataItem& value ) { return AEPutParamPtr(&fMessage, key, value.GetDataType(), (char*) value.GetPhysicalStart(), value.GetPhysicalLength() ); }
  154.  
  155. /***********************************|****************************************/
  156.  
  157. #pragma pop
  158.  
  159. #endif    // __UAPPLEEVENTS__
  160.  
  161.  
  162.  
  163.